home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / a86b.arc / D_INIT.DOC < prev    next >
Encoding:
Text File  |  1986-08-13  |  4.6 KB  |  92 lines

  1. ---D_INIT.DOC---
  2.  
  3. Data Allocation Using DB, DW, DD, DQ, and DT
  4.  
  5. The 86 computer family supports the three fundamental data types BYTE, WORD,
  6. and DOUBLEWORD. A byte is eight bits, a word is 16 bits (2 bytes), and a
  7. doubleword is 32 bits (4 bytes).   In addition, the 87 floating-point processor
  8. manipulates 8-byte quantities, which we call Q-words, and 10-byte quantities,
  9. which we call T-words. The A86 data allocation statement is used to specify the
  10. bytes, words, doublewords, Q-words, and T-words which your program will use as
  11. data. The syntax for the data allocation statement is as follows:
  12.  
  13. (optional var-name)  DB  (list of values)
  14. (optional var-name)  DW  (list of values)
  15. (optional var-name)  DD  (list of values)
  16. (optional var-name)  DQ  (list of values)
  17. (optional var-name)  DT  (list of values)
  18.  
  19. The variable name, if present, causes that name to be entered into the symbol
  20. table as a memory variable with type BYTE (for DB), WORD (for DW), DWORD (for
  21. DD), QWORD (for DQ), or TWORD (for DT). The variable name should NOT have a
  22. colon after it, unless you wish the name to be a label (instructions referring
  23. to it will interpret the label as the constant pointer to the memory location,
  24. not its contents).
  25.  
  26. The DB statement is used to reserve bytes of storage; DW is used to reserve
  27. words.  The list of values to the right of the DB or DW serves two purposes.  It
  28. specifies how many bytes or words are allocated by the statement, as well as
  29. what their initial values should be.  The list of values may contain a single
  30. value or more than one, separated by commas.  The list can even be missing;
  31. meaning that we wish to define a byte or word variable at the same location as
  32. the next variable.
  33.  
  34. If the data initialization is in the DATA segment, the values given are ignored,
  35. except as place-markers to reserve the appropriate number of units of storage.
  36. The use of "?", which is a synonym for zero, is recommended in this context to
  37. emphasize the lack of actual memory initialization.
  38.  
  39. A special value which can be used in data initializations is the DUP construct,
  40. which allows the allocation and/or initialization of blocks of data.  The
  41. expression  n DUP (x)  is equivalent to a list with x repeated n times.  "x" can
  42. be either a single value, a list of values, or another DUP construct nested
  43. inside the first one.
  44.  
  45. Here are some examples of data initialization statements, with and without DUP
  46. constructs:
  47.  
  48. CODE SEGMENT
  49.   DW 5                    ; allocate one word, initialized to 5
  50.   DB 0,3,0                ; allocate three bytes, initialized to 0,3,0
  51.   DB 5 DUP (0)            ; equivalent to DB 0,0,0,0,0
  52.   DW 2 DUP (0,4 DUP (7))  ; equivalent to DW 0,7,7,7,7,0,7,7,7,7
  53.  
  54. DATA SEGMENT
  55. XX      DW ?      ; define a word variable XX
  56. YYLOW   DB        ; no init value: YYLOW is the low byte of word variable YY
  57. YY      DW ?
  58. X_ARRAY DB  100 DUP (?)   ; X_ARRAY is a 100-byte array
  59. D_REAL  DQ ?              ; double-precision floating variable
  60. EX_REAL DT ?              ; extended precision floating variable
  61.  
  62. A character string value may be used to initialize consecutive bytes in a DB
  63. statement.  Each character will be represented by its ASCII code.  The
  64. characters are stored in the order that they appear in the string, with the
  65. first character assigned to the lowest-addressed byte.  In the DB statement that
  66. follows, five bytes are initialized with the ASCII representation of the
  67. characters in the string 'HELLO':
  68.  
  69. DB 'HELLO'
  70.  
  71. Note that the DB directive is the only place in your program that strings of
  72. length greater than 2 may occur.  In all other contexts (including DW), a string
  73. is treated as the constant number represent the ASCII value of the string; for
  74. example, CMP AL,'#' is the instruction comparing the AL-register with the ASCII
  75. value of the pound-sign.  Note further that 2-character string constants, like
  76. all constants in the 8086, have their bytes reversed.  Thus, while DB 'AB' will
  77. produce hex 41 followed by hex 42, the similar-looking DW 'AB' reverses the
  78. bytes: hex 42 followed by hex 41.
  79.  
  80. The DD directive is used to initialize 32-bit doubleword pointers to loactions
  81. in arbitrary segments of the 86's memory space.  Values for such pointers
  82. are given by two numbers separated by a colon.  The segment register value
  83. appears to the left of the colon; and the offset appears to the right of the
  84. colon.  In keeping with the reversed-bytes nature of memory storage in the 86
  85. family, the offset comes forst in memory.  For example, the statement
  86.  
  87.    DD 01234:05678
  88.  
  89. appearing in a CODE segment will cause the hex bytes 78 56 34 12 to be
  90. generated, which is a long pointer to segment 01234, offset 05678.
  91.  
  92.